<template>
  <div
    class="menu-demo"
    :style="{
      boxSizing: 'border-box',
      width: '100%',
      padding: '20px',
    }"
  >
      <a-breadcrumb :max-count="4">
        <a-breadcrumb-item>Home</a-breadcrumb-item>
        <a-breadcrumb-item>Sub Home</a-breadcrumb-item>
        <a-breadcrumb-item>All Channel</a-breadcrumb-item>
        <a-breadcrumb-item>Channel</a-breadcrumb-item>
        <a-breadcrumb-item>News</a-breadcrumb-item>
        <a-breadcrumb-item>Post</a-breadcrumb-item>
      </a-breadcrumb>
      <a-table
        :columns="columns"
        :data="file_data"
        :bordered="true"
        :hoverable="true"
        :stripe="true"
        :loading="file_loading"
        :show-header="true"
        :style="{width:'100%'}"
        :checkbox="true"
      />
  </div>
</template>
<script>
import { Modal, Button } from "@arco-design/web-vue";
import { ref } from "vue";
import axios from "axios";
import { onMounted } from "vue";
export default {
  setup() {
    const file_data = ref([]);
    const file_loading = ref(true);
    onMounted(() => {
      get_file_data();
    });
    const columns = [
      {
        title: "文件名",
        dataIndex: "file_name",
      },
      {
        title: "文件大小",
        dataIndex: "file_size",
      },
      {
        title: "权限/所有者",
        dataIndex: "file_auth",
      },
      {
        title: "修改时间",
        dataIndex: "file_time",
      },
      {
        title: "操作",
        dataIndex: "action",
        fixed: 'right'
      },
    ];
    function get_file_data() {
      axios;
      let data;
      if (localStorage.getItem("file/path") == null) {
        data = {
          path: "./",
        };
      } else {
        data = {
          path: localStorage.getItem("file/path"),
        };
      }
      console.log(data);
      axios
        .post("/api/post/get_file_data", data)
        .then((response) => {
          // 处理成功响应
          console.log("成功响应:", response.data);
          file_data.value = [];
          response.data.data.forEach(function (element) {
            file_data.value.push({
              file_name: element.name,
              file_size: element.size,
              file_path: element.auth,
              file_time: element.time,
              action: "删除",
            });
            file_loading.value = false;
          });
        })
        .catch((error) => {
          // 处理错误
          console.error("请求错误:", error);
        });
    }

    return {
      file_data,
      file_loading,
      columns,
    };
  },
  methods: {},
  components: {
    Modal,
    Button,
  },
};
</script>
